package com.fansl.allround.open.helper.mail;

import com.fansl.allround.common.core.util.SpringContextHolder;
import com.fansl.allround.open.api.entity.email.SendMailMessage;
import com.fansl.allround.open.api.entity.email.SendMailMessagePO;
import lombok.extern.slf4j.Slf4j;

/**
 * @author fansl
 * @Description: 邮箱消息模板生成策略
 * @date 2019/10/10 14:19
 */
@Slf4j
public class EmailMessageTemplateContext {
    private EmailMessageTemplateExecutor emailMessageTemplateExecutor;
    private SendMailMessagePO mailMessage;

    public EmailMessageTemplateContext(SendMailMessagePO mailMessage){
        this.mailMessage = mailMessage;
        builder();
    }

    private void builder(){
        switch (mailMessage.getEmailMessageType()){
            case REGISTER:
                emailMessageTemplateExecutor = SpringContextHolder.getBean(RegisterMessageTemplateExecutor.class);
                break;
        }
    }
    public SendMailMessage execute() throws Exception{
        if(emailMessageTemplateExecutor!=null){
            return emailMessageTemplateExecutor.createMessageTemplate(mailMessage);
        }
        return null;
    }
}
